<?php
namespace App\Services\SubmitForm\SubmitForm;

use App\Models\SubmitForm\SubmitForm;
use Illuminate\Support\Facades\DB;
use App\Services\Manage\ManageIndex;
/**
 * SubmitForm 逻辑层
 * Class GoodsLogic
 * @package App\Services\SubmitForm\SubmitForm
 */
class SubmitFormLogic 
{
    /*我的 - 提交意见建议*/
   /* public function suggestion($data): array 
    {
        $form_content = [];
        foreach ($data as $k => $v) {
            if(!in_array($k, ['user_id','user_info','app_id'])){
                $form_content[$k] = $v;
            }
        }
        $data['form_content'] = $form_content;
        $res = $this->model($this->submitformModel)->allowField(['app_id','user_id','user_info','form_content','create_time','update_time'])->save($data);
        return auto_return($res);

    }*/

    /*后台 - 获取意见建议列表*/
    public function getSuggestionList($data): array 
    {
        //获得总后台的APP_id
        $manageAppId = ManageIndex::Api()->getAppId();
        $app_id = $data['app_id'];
        $keywords = $data['keywords'];
        $re = SubmitForm::where('status', '=', 1);          
        if($manageAppId != $app_id){
            $re->where('app_id','=',$app_id);
        }
        if($data['keywords'] != ''){
            $re->where('user_info->name','like',"%{$keywords}%");
        }  
        $res = $re->orderBy('id', 'desc')->paginate($data['listRows'], null, null, $data['page'])->toArray();
        return auto_return_page($res, '已找到意见建议列表数据', '没有意见建议列表数据');
    }

    /*标记某表单已阅读*/
    public function remarkRead($data): array 
    {
        $res = SubmitForm::where([['status', '=', 1],['is_read','=',0],['id','=',$data['id']]])->update(['is_read'=>1]);   
        return auto_return($res);
    }
    

}